﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Program17
{
    class Program
    {
        static void Main(string[] args)
        {
            //暂停1秒
            //Thread.Sleep(1000);
            //Console.WriteLine("aaaa");
            Program p = new Program();
            //p.Con();

            //创建另一个线程
            //ThreadStart ts = new ThreadStart(p.Con);
            //Thread thread = new Thread(ts);
            //thread.Start();

            Console.WriteLine("主线程");
            Thread thread = new Thread(new ThreadStart(ThreadProc));
            thread.Start();
            
            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine("主线程做别的事");
            }
            //Join 阻塞调用线程，直到某个线程执行完成
            thread.Join();
            Console.WriteLine("主线程要等待");
            Console.ReadLine();
        }
        public void Con()
        {
            int i = 1;
            int j = 2;
            int result = i + j;
            Console.WriteLine("线程：{0}  计算结果：{1}", AppDomain.GetCurrentThreadId().ToString(), result);
        }
        public static void ThreadProc()
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("ThreadProc" + i);

            }
        }
    }
}
